Page({
  data: {
    // 设置项列表
    settings: [
      { id: 1, name: '消息通知', type: 'switch', enabled: true },
      { id: 2, name: '隐私设置', type: 'switch', enabled: false },
      { id: 3, name: '自动登录', type: 'switch', enabled: true },
      { id: 4, name: '推送设置', type: 'switch', enabled: false },
      { id: 11, name: '夜间模式', type: 'switch', enabled: false },
      { id: 5, name: '修改密码', type: 'button', buttonText: '修改密码', url: '/pages/my/editPassword/editPassword' },
      { id: 6, name: '修改昵称', type: 'button', buttonText: '修改昵称', url: '/pages/my/editNickname/editNickname' },
      { id: 7, name: '语言设置', type: 'button', buttonText: '设置语言', url: '/pages/my/languageSettings/languageSettings' },
      { id: 8, name: '清除缓存', type: 'button', buttonText: '清除缓存', url: '/pages/my/clearCache/clearCache' },
      { id: 9, name: '关于我们', type: 'button', buttonText: '关于我们', url: '/pages/my/aboutUs/aboutUs' },
      { id: 10, name: '隐私政策', type: 'button', buttonText: '隐私政策', url: '/pages/my/privacyPolicy/privacyPolicy' },
    ]
  },

  // 切换设置项的开关
  toggleSetting(e) {
    const settingId = e.currentTarget.dataset.id;
    const settings = this.data.settings;
    const index = settings.findIndex(set => set.id === settingId);
    if (index !== -1) {
      settings[index].enabled = !settings[index].enabled; // 切换状态
      this.setData({ settings });
    }
  },

  // 跳转到其他页面
  navigateToPage(e) {
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    });
  },

  // 退出登录
  logout() {
    wx.showModal({
      title: '确认退出登录?',
      content: '退出后您将无法访问个人数据。',
      success: (res) => {
        if (res.confirm) {
          wx.clearStorage();  // 清除本地存储
          wx.redirectTo({
            url: '/pages/login/login'  // 跳转到登录页面
          });
        }
      }
    });
  }
});
